﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Agency_Tra_NoComp_NoLimit_goods : System.Web.UI.Page,HZ.MBSM.BLL.TraDes
{
    int projectid;
    string strSql;
   
    protected void Page_Load(object sender, EventArgs e)
    {
         if(HZ.MBSM.BLL.Login.CheckAssert(this.UseAccountType))
         {
          projectid = SysFun.ToInt(SysFun.IsSQL(Request.QueryString["projectid"]));
         }
         
        databain();
    }
    /// <summary>
    /// 数据绑定
    /// </summary>
    public void databain()
    {
        int i = 0;
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "BidGoods_View";                                        //要查询的表明
        dbPage.Key = "BidId";                                         　　　　 //表的主键    
        dbPage.Where = selectWhere();                                           　//查询条件    
        dbPage.SelectField = "BidId,GoodsId,ProductName,GoodsName,Medicinemodel,Outlookc,Unit,Factor,factoryName,FactoryUserCode";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request.QueryString["PG"]);            　 //设置需要查询第几页
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]); 　　　　　//设置需要查询第几页
        dbPage.PageSize = 30;                                                　   //设置每页显示多少条记录 
        dbPage.OrderBy = "BidId";                  　　　　　　　　　　　　　　　//排序字段

        System.Data.IDataReader dr = dbPage.ExecuteReader();
        System.Text.StringBuilder sbt = new System.Text.StringBuilder();
        sbt.Append("<table width='98% style='border-collapse: collapse' >");
        sbt.Append("<tr class='table_title' nowrap>");
        sbt.Append("<td nowrap style='word-break:break-all' width='9%'>商品流水号</td>");
        sbt.Append("<td nowrap style='word-break:break-all' width='14%'>通用名</td>");
        sbt.Append("<td nowrap style='word-break:break-all' width='13%'>商品名</td>");
        sbt.Append("<td nowrap style='word-break:break-all' width='9%'>剂型</td>");
        sbt.Append("<td nowrap style='word-break:break-all' width='11%'>规格</td>");
        sbt.Append("<td nowrap style='word-break:break-all' width='4%'>转换系数</td>");
        sbt.Append("<td nowrap style='word-break:break-all' width='4%'>制剂单位</td>");
        sbt.Append("<td nowrap style='word-break:break-all' width='8%'> 生产企业注册号</td>");
        sbt.Append("<td nowrap style='word-break:break-all' width='15%'>生产企业</td>");
        sbt.Append("<td nowrap style='word-break:break-all' width='4%'>维护</td>");
        sbt.Append(" </tr>");
       
        while (dr.Read())
        {
            if (i == 0)
            {
                sbt.Append("<tr class='table_td'>");
                i++;
            }
            else
            {
                sbt.Append("<tr class='table_td2'>");
                i--;
            }
          
            sbt.Append("<td align='center'>" + SysFun.ToTrim(dr["GoodsId"]) + "</td>");
            sbt.Append("<td align='left'>" + SysFun.ToTrim(dr["ProductName"]) + "</td>");
            sbt.Append("<td align='left'>" + SysFun.ToTrim(dr["GoodsName"]) + "</td>");
            sbt.Append("<td align='left'>" + SysFun.ToTrim(dr["Medicinemodel"]) + "</td>");
            sbt.Append("<td align='left'>" + SysFun.ToTrim(dr["Outlookc"]) + "</td>");
            sbt.Append("<td align='center'>" + SysFun.ToTrim(dr["Factor"]) + "</td>");
            sbt.Append("<td align='left'>" + SysFun.ToTrim(dr["Unit"]) + "</td>");
            sbt.Append("<td align='left'>" + SysFun.ToTrim(dr["FactoryUserCode"]) + "</td>");
            sbt.Append("<td align='left'>" + SysFun.ToTrim(dr["factoryName"]) + "</td>");
            sbt.Append("<td align='left'>" + "<a target= _blank  href='Tra_No_No_change.aspx?GoodsId=" + dr["GoodsId"] + "&projectid=" + projectid + "'>" + "维护" + "</a> </td>");
   
            sbt.Append("</tr>");

        }
       
        sbt.Append("</table>");

        Label1.Text = sbt.ToString();
        dr.Close();
        dr.Dispose();
        db.Close();
        dbPage.Db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键
       
      
    }
    private string selectWhere() //查询条件    
    {
        //在视图　BidGoods_View　中查找　goodsid 不在　表SupplyPlan_Goods　中GoodsState＝２（不竟价不限价）的所有　CheckStatus='1'(审核通过),Status=2 （不竟价不限价）商品　isbid　中标
        strSql = " goodsid not in( select goodsid from SupplyPlan_Goods where ProjectId =" + projectid + ") and CheckStatus=1 and Status=2 and spprice >0 and isbid=1 and ProjectId=" + projectid + " ";
        if (Request.Form["PurchaseChoose"] == "查询")
        {
            string _txtGoodsId, _txtProductName, _Text_GoodsName, _Text_CompanyName_SC, _TextMedicinemodel, _TextOutlookc, _txtProductNameX;
            _txtGoodsId = txtGoodsId.Text.Trim().ToString();
            _txtProductName = txtProductName.Text.Trim().ToString();
            _txtProductNameX = TextBox1.Text.Trim();
            _Text_GoodsName = Text_GoodsName.Text.Trim().ToString();
            _Text_CompanyName_SC = Text_CompanyName_SC.Text.Trim().ToString();
            _TextMedicinemodel = TextMedicinemodel.Text.Trim().ToString();
            _TextOutlookc = TextOutlookc.Text.Trim().ToString();
            if (_txtGoodsId != "")
            {
                strSql = strSql + " and GoodsId=" + _txtGoodsId ;
            }
            if (_txtProductName != "")
            {
                strSql = strSql + " and (ProductName like '%" + _txtProductName + "%' or SpellingCode like '%" + _txtProductName + "%')";
            }
            if (_txtProductNameX != "")
            {
                strSql = strSql + " and (ProductName = '" + _txtProductNameX + "' or SpellingCode = '" + _txtProductNameX + "')";
            }
            if (_Text_GoodsName != "")
            {
                strSql = strSql + " and GoodsName like '%" + _Text_GoodsName+ "%'";
            }
            if (_Text_CompanyName_SC != "")
            {
                strSql = strSql + " and factoryName like '%" + _Text_CompanyName_SC + "%'";
            }
            if (_TextMedicinemodel != "")
            {
                strSql = strSql + " and Medicinemodel like '%" + _TextMedicinemodel + "%'";
            }
            if (_TextOutlookc != "")
            {
                strSql = strSql + " and Outlookc like '%" + _TextOutlookc + "%'";
            }
        }
        return strSql;
        
    }
   protected void Button1_Click(object sender, EventArgs e)//导入到挂网目录
   {
       string StrSql = "";
       Db db = new Db();
       System.Data.IDataReader dr;
       StrSql = "Select Top 10 * From project_bid where projectid=" + projectid.ToString() + " and isbid='1'";//检查是否已经投标结束
       dr = db.DataReader(StrSql);
       if (dr.Read())
       {

       }
       else
       {
           Response.Write("<script>window.alert('对不起，没有中标数据，该功能不能使用');</script>");
           Response.Write("<script>window.location.href='Compete.aspx?projectid=" + projectid + "'</script>");
       }
       dr.Close();
       //检查是否已经完成
       StrSql = "Select Top 10 * From SupplyPlan_Goods Where Projectid=" + projectid + " and GoodsState=2";
       dr = db.DataReader(StrSql);
       if (dr.Read())
       {
           dr.Close();
           dr.Dispose();
           Response.Write("<script>window.alert('已经导入过了，请执行其他步骤！');</script>");

       }
       else
       {
           dr.Close();
           dr.Dispose();
           //直接将不竟价不限价的中标结果导入到配送目录表中
           StrSql = "insert into SupplyPlan_Goods( ProjectId, ProductId, ProductName, MedicineModel, Outlookc, ProductCode, BidTableName,BidTableType, BidTableOutlookc, GoodsId, GoodsName, QualityLevels, Pack, Factor, PackUnit, AccountId_SC,CompanyName_SC, AccountId_Agent, CompanyName_Agent, AccountId_TB, CompanyName_TB, AccountId_PS, CompanyName_PS,BidPrice, GoodsState,UserCode_TB,UserCode_PS,UserCode_SC,FrontSortId,FrontSortName,Sortid,SortName) select ProjectId, ProductId, ProductName, MedicineModel, Outlookc, ProductCode, BidTableName, BidTableType, BidTableOutlookc, GoodsId, GoodsName, QualityLevels, Pack, Factor, PackUnit, AccountId_SC, CompanyName_SC, AccountId_Agent, CompanyName_Agent, AccountId_TB, CompanyName_TB, AccountId_PS, CompanyName_PS,BidPrice,'2',UserCode_TB,UserCode_PS,UserCode_SC,FrontSortId,FrontSortName,Sortid,SortName  from TradeDataList where projectid=" + projectid.ToString() + " and isbid='1' and status=2  ";
           db.Command(StrSql);
       }
       db.Close();
    }
   

    #region TraDes 成员

    public string Name
    {
        get { return "不竟价不限价商品维护"; }
    }

    public string Describe
    {
        get { return ""; }
    }

    public string ParentName
    {
        get { return "挂网目录管理"; }
    }

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
            return _AccountType;
        }
    }

    #endregion


 
   
}
